package server;

import java.nio.charset.StandardCharsets;

/**
 * @author Y1n
 * @date 2021/11/19 13:35
 * @decs http协议工具类 提供响应头信息 只提供200 和404
 **/
public class HttpPortocolUtil {


    /**
     * @author Y1n
     * @date 2021/11/19 13:42
     * @description 200 头信息
     * @param
     * @return
     */
    public static String getHttpHeaderSuccess(long contentLength){
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length: " + contentLength + " \n" +
                "\r\n";
    }


    /**
     * @author Y1n
     * @date 2021/11/19 13:41
     * @description 404 头信息
     * @param
     * @return
     */
    public static String getHttpHeaderFail(){
        String strFail = "<h1>404 not found</h1>";
        return "HTTP/1.1 404 Not Found \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length: " + strFail.getBytes(StandardCharsets.UTF_8).length + " \n" +
                "\r\n" + strFail;
    }

}
